﻿/****************************************************
	文件：DotNetExtension.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/12/20 10:29:52
	功能：.Net 扩展
*****************************************************/

using System;
using System.Collections;
using System.Collections.Generic;

namespace HTFW.Utility.Global
{
    /// <summary>
    /// 类 扩展方法
    /// </summary>
    public static class ClassExtension
    {
        public static bool IsNull<T>(this T self) where T : class
        {
            return self == null;
        }

        public static bool IsNotNull<T>(this T self) where T : class
        {
            return self != null;
        }
    }

    /// <summary>
    /// 集合 扩展方法
    /// </summary>
    public static class CollectionsExtension
    {
        public static bool IsNull(this ICollection array)
        {
            return array == null;
        }

        public static bool IsNullOrEmpty(this ICollection array)
        {
            if (array == null) return true;
            return array.Count == 0;
        }

        static Random mRand = new Random();

        /// <summary>
        /// 洗牌
        /// </summary>
        /// <param name="list"></param>
        /// <typeparam name="T"></typeparam>
        public static void Shuffle<T>(this IList<T> list)
        {
            int i = list.Count;
            while (i > 1)
            {
                i--;
                int index = mRand.Next(i + 1);
                T value = list[index];
                list[index] = list[i];
                list[i] = value;
            }
        }
    }

    /// <summary>
    /// 字符 串扩展方法
    /// </summary>
    public static class StringExtension
    {
        public static bool IsNullOrEmpty(this string self)
        {
            return string.IsNullOrEmpty(self);
        }
    }
}